/**
 * 执行的SQL：
 * CREATE OR REPLACE PROCEDURE hr.myproc (id IN NUMBER, name OUT STRING) AS
 * BEGIN
 *  SELECT last_name INTO name FROM employees WHERE employee_id = id;
 * END;
 */

import oracle = require("oracledb");
import dbConfig = require("../config/dbConfig");

let config = dbConfig.config;

oracle.getConnection(config)
    .then(function(connection){
        return connection.execute(
            "BEGIN hr.myproc(:id, :name); END;",
            {  // bind variables
              id:   159,
              name: { dir: oracle.BIND_OUT, type: oracle.STRING, maxSize: 40 },
            }
        )
        .then(function(result){
            console.log(result);
            console.log(result.outBinds);
            return connection.close();
        })
        .catch(function(err){
           console.error(err.message);
           return connection.close(); 
        });
    })
    .catch(function(err){
        console.error(err.message);
    });
